<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>我的订单</title>
	<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
	<script src="/layer.js"></script>
	<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.js"></script>
	<link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.css" rel="stylesheet">
	<style>
		.layui-layer-btn1 {
			color: black !important;
		}
	</style>
</head>
<body>
<br>
<br>
<div class="container">
	<h1>我的订单</h1>
	<form action="/order/find">
		<input type="hidden" name="username" value="${RequestParameters['username']}">
		<div class="row">
			<label  class="my-1 mr-2 " style="margin-left: 17px;">限制时间</label>
			<div class="col col-md-6">
				
				<input type="date" class="form-control" name="startDate"<#if RequestParameters['startDate']??> value="${RequestParameters['startDate']}" </#if>>
				<input type="date" class="form-control" name="endDate" <#if RequestParameters['endDate']??> value="${RequestParameters['endDate']}" </#if>>
			</div>
			<div class="col col-md-4">
				<input type="submit" class="btn btn-primary" value="查询"/>
				<a href="/order?username=${RequestParameters['username']}" class="btn btn-primary">显示所有</a>
			</div>
		</div>
	</form>
	<br>
<#if list??>
	<table class="table" style="text-align: center">
		<thead class="thead-dark">
		<tr>
			<th scope="col">id</th>
			<th scope="col">下单人</th>
			<th scope="col">购买物品</th>
			<th scope="col">状态</th>
			<th scope="col">下单时间</th>
			<th scope="col">操作</th>
		</tr>
		</thead>
		<tbody>
		<#list list as l>
			<tr>
				<th scope="row">${l.key.id}</th>
				<td>${l.key.customer}</td>
				<td>
					
					<#list l.val?values as d>
						${d.goods.name}-${d.goods.price} x ${d.count}
						<br>
					</#list>
				</td>
				<td>${l.key.state.getName()}</td>
				<td>${l.key.createTime}</td>
				<td>
					<form action="/order/cancel" method="post">
						<input type="hidden" name="origin">
						<input type="hidden" name="id" value="${l.key.id}">
						<a href="#" class="btn btn-primary">付款</a>
						<#if l.key.state='CANCEL'>
							<button type="submit" class="btn btn-info"
						            onclick="return active(this)">激活
							</button>
						<#else>
							<button type="submit" class="btn btn-warning"
							        onclick="return cancle(this)">取消
							</button>
						</#if>
					</form>
				</td>
			</tr>
		</#list>
		</tbody>
	</table>

<#else>
不考虑先买点？
</#if>
<a href="/category/">继续购物</a>
<script>
	$("[name='origin']").val(location.href.substring(location.href.indexOf("/",8)));
	
	function active(ele) {
		layer.msg('确认激活？', {
			time: 0
			,btn: ['是', '否']
			,yes: (index) => {
				layer.close(index);
				$(ele).parent().attr("action","/order/active");
				$(ele).parent().submit();
			}
		});
		return false;
	}
	
	function cancle(ele) {
		layer.msg('确认取消？', {
			time: 0
			,btn: ['是', '否']
			,yes: (index) => {
				layer.close(index);
				$(ele).parent().submit();
			}
		});
		return false;
	}
</script>
</div>
</body>
</html>